package src.Main;

import sun.misc.Unsafe;

import java.io.IOException;
import java.nio.file.FileVisitResult;
import java.nio.file.FileVisitor;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.attribute.BasicFileAttributes;
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;
import java.util.concurrent.ConcurrentSkipListSet;

public class Convert {
    public static void main(String[] args) {
        String root = "C:\\Users\\SWQXDBA\\AppData\\Roaming\\SpaceEngineers\\Mods\\新档core\\Data";
        List<Path> targets = new ArrayList<>();
        System.out.println("1: xml->sbc");
        System.out.println("2: sbc->xml");
            Scanner scanner = new Scanner(System.in);
        final int i = scanner.nextInt();
        try {

            Files.walkFileTree(Path.of(root), new FileVisitor<Path>() {
                @Override
                public FileVisitResult preVisitDirectory(Path dir, BasicFileAttributes attrs) throws IOException {


                    return FileVisitResult.CONTINUE;
                }

                @Override
                public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException {
                    targets.add(file);
                    return FileVisitResult.CONTINUE;
                }

                @Override
                public FileVisitResult visitFileFailed(Path file, IOException exc) throws IOException {
                    return FileVisitResult.CONTINUE;
                }

                @Override
                public FileVisitResult postVisitDirectory(Path dir, IOException exc) throws IOException {
                    return FileVisitResult.CONTINUE;
                }
            });
        } catch (IOException e) {
            e.printStackTrace();
        }
        targets.forEach((path -> {
            try {
                if(i==1){
                    Files.move(path,Path.of(path.toString().replace(".xml",".sbc")));

                }else if(i==2){
                    Files.move(path,Path.of(path.toString().replace(".sbc",".xml")));
                }else{
                    System.out.println("错误的选项 exit..");
                }

            } catch (IOException e) {
                e.printStackTrace();
            }
        }));

    }
}
